/**
 * StrUtil.java
 * Created at 2017-4-7
 * Created by shihui
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.common.utils;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>ClassName: StrUtil</p>
 * <p>Description: 字符处理工具类</p>
 * <p>Author: shihui</p>
 * <p>Date: 2017-4-7</p>
 */
public class StrUtil {
    
    /**
     * 离线报文文件存放路径
     */
    public static final String OFFLINE_MESSAGE_PATH = "D:\\Lishen_BMS_OFFLINE_MESSAGE";
    /**
     * 历史告警数据回传根目录路径
     */
    public static final String ALERT_PATH = "D:/Lishen_BMS_Message/";
    
    /**
     * 告警文件前缀
     */
    public static final String ALERT_PATH_PREFIX = "LS_";
    
    /**
     * 文件路径分隔符
     */
    public static final String FILE_SEPARATOR = "/";

    /**
     * 分钟
     */
    public static final int MINUTE = 60;
    
    /**
     * 毫秒
     */
    public static final int MILLISECOND = 1000;
    
    /**
     * 字符：1
     */
    public static final String ONE = "1";

    /**
     * 执行时间间隔
     */
    public static final long TIME_INTERVAL = 5000;

    /**
     * 数据回传保存默认路径，仅当数据库无相关配置时使用
     */
    public static final String ZIP_DEFAULT_PATH = "D:/Lishen_BMS_Message_ZIP";

    /**
     * .zip 后缀
     */
    public static final String ZIP_SUFFIX = ".zip";

    /**
     * 
     * <p>Description: 字符串的trim方法</p>
     * @param str 字符串
     * @return 结果
     */
    public static String strTrim(String str) {
        String result;
        if (str == null) {
            result = "";
        } else {
            result = str.trim();
        }
        return result;
    }
    
    /**
     * 
     * <p>Description: 验证字符串是否为空</p>
     * @param str 字符串
     * @return 验证结果
     */
    public static Boolean isEmpty(String str) {
        if (str != null && !str.isEmpty()) {
            return false;
        }
        return true;
    }
    
    /** 
     * List转换String 取出每条中的command
     *  
     * @param list 
     *            :需要转换的List 
     * @return String转换后的字符串 
     */  
    public static List<String> ListToString(List<String> list) {  
        List<String> result;
        result = new ArrayList<String>();
        if (list != null && list.size() > 1) {  
            list.remove(0);
            for (int i = 0; i < list.size(); i++) {  
                if (list.get(i) == null || list.get(i) == "") {  
                    continue;  
                }  
                result.add(list.get(i).substring(list.get(i).indexOf(",")+1, list.get(i).lastIndexOf(",")));
                
            }  
        }  
        return result;  
    } 
}
